package asteroids.model.programs.parsing.statements;

import java.util.Map;

import asteroids.model.CollisionObject;
import asteroids.model.programs.parsing.expressions.E;

public class IfThenElse extends S {

	public IfThenElse(int line, int column, E condition, S then, S otherwise) {
		super(line, column);
		setCondition(condition);
		setThen(then);
		setOtherwise(otherwise);
	}
	public boolean isGoodCondition(Map<String,E> map, CollisionObject collisionObject){
		if(getCondition().isString() || getCondition().isBoolean()){
			if(getCondition().getContent(map, collisionObject).getClass() == Boolean.class){
				return true;
			}
		}
		return false;
	}
	public void setCondition(E condition){
		this.condition = condition;
	}
	
	public E getCondition(){
		return this.condition;
	}
	
	public void setThen(S then){
		this.then = then;
	}
	
	public S getThen(){
		return this.then;
	}
	
	public void setOtherwise(S otherwise){
		this.otherwise = otherwise;
	}
	
	public S getOtherwise(){
		return this.otherwise;
	}
	
	private E condition;
	private S then;
	private S otherwise;

	@Override
	public void execute(ExecuteManager executeManager) {
		executeManager.execute(this);
	}
	public void redo(){
		if(getExecuted()){
			getThen().redo();
			getOtherwise().redo();
		}
		super.redo();
	}


}
